define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
    var Controller = {
        index: function () {
            //
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'dealer/index',
                    add_url: 'dealer/add',
                    edit_url: '',
                    del_url: 'dealer/del',
                    multi_url: 'dealer/multi',
                    table: '',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                searchFormVisible: true,
                searchFormTemplate: 'customformtpl',
                columns: [
                    [
                        { field: 'id', title: 'ID', operate: false },
                        { field: 'username', title: __('Username') },
                        { field: 'qr_code', title: __('邀请码') },
                        { field: 'address', title: __('区域') },
                        { field: 'performance', title: __('个人业绩') },
                        { field: 'direct_thrust_performance', title: __('团队业绩') },
                        {
                            field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate, buttons: [
                                {
                                    name: '个人业绩',
                                    title: '个人业绩',
                                    text: '个人业绩',
                                    extend: 'data-area=["90%","90%"]',
                                    classname: 'btn btn-primary btn-xs btn-view btn-dialog',
                                    url: 'order/order/performance?uid={id}',//接口地址 控制器名/方法名
                                },
                                {
                                    name: '团队业绩',
                                    title: '团队业绩',
                                    text: '团队业绩',
                                    extend: 'data-area=["90%","90%"]',
                                    classname: 'btn btn-primary btn-xs btn-view btn-dialog',
                                    url: 'order/order/direct_thrust_performance?uid={id}',//接口地址 控制器名/方法名
                                },
                            ]
                        },

                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
